package at.ac.univie.bi.transformation.service.input;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import at.ac.univie.bi.transformation.model.input.Medication;
import at.ac.univie.bi.transformation.model.input.Patient;
import at.ac.univie.bi.transformation.persistence.DBHandler;

public class MedicationService extends AbstractInputEntityService {
	
	List<Medication> medications = new ArrayList<Medication>();
	
	public static List<Medication> selectMedications()
	  {
		  String tableName = "Medikation";
		  List<Medication> medications = new ArrayList<Medication>();
		  Statement stmt = null;
		  Connection oldDB = DBHandler.getOldDB();
		  
	      try
	      {
	          stmt = oldDB.createStatement();
	          ResultSet results = stmt.executeQuery("select * from " + tableName);
	          

	          while(results.next())
	          {
	              int patientID = results.getInt("patientId");
	              String bezeichnung = results.getString("bezeichnung");
	              Timestamp ausgabeDate = results.getTimestamp("ausgabe");
	              int dosis = results.getInt("dosis");
	              
	              Medication newMedication = new Medication();
	              newMedication.setPatientId(patientID);
	              newMedication.setBezeichnung(bezeichnung);
	              newMedication.setAusgabe(ausgabeDate);
	              newMedication.setDosis(dosis);
	              
	              medications.add(newMedication);
	          }
	          results.close();
	          stmt.close();

	      }
	      catch (SQLException sqlExcept)
	      {
	          sqlExcept.printStackTrace();
	      }
	      
	      
	      return medications;
	  }

	@Override
	public void readAll() {
		// TODO Auto-generated method stub
		
	}
}
